<template>
<!--用于入库信息查看时供应商下拉,获取全部的供应商-->
  <div>
    <a-space>
      <a-select
        v-model="values"
        optionFilterProp="label"
        show-search
        placeholder=""
        style="width: 200px"
        @change="handerChange"
        :disabled="isDisabled"
      >
        <a-select-option v-for="item in options" :key="item.id" :value="item.id" :label="item.name">{{
          item.name
        }}</a-select-option>
      </a-select>
    </a-space>
  </div>
</template>

<script>
import Vue from 'vue'
import { AntDesignOutline, DashboardOutline, TwitterOutline, SearchOutline } from '@ant-design/icons'
import AntdIcon from '@ant-design/icons-vue'
AntdIcon.add(AntDesignOutline, DashboardOutline, SearchOutline)
Vue.use(AntdIcon)

import ErpLocationList from '@/views/modules/location/ErpLocationList'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import { getAction } from '@api/manage'
import { ajaxGetDictItems } from '@api/api'

export default {
  name: 'TslMateralSupplier',
  describes: '根据物料选择供应商',
  props: {
    value: {
      type: String,
      required: false,
      default: '',
    },
    rowData: {
      type: Object,
      required: false,
    },
    isDisabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    materialId: {
      type: String,
      required: false,
    },
    procurementDetailId: {
      type: String,
    },
    containDelete: {
      type: Boolean,
    },

    // list: {
    //   type: Array,
    //   required: true
    // },
    // currentStatus: {
    //   type: Number,
    //   default: 0,
    //   required: false
    // }
  },
  mixins: [mixinDevice],
  components: {
    ErpLocationList,
  },
  data() {
    return {
      values: this.value,
      url: {
        list: '/base/erpLocation/list',
        delete: '/base/erpLocation/delete',
        deleteBatch: '/base/erpLocation/deleteBatch',
        exportXlsUrl: '/base/erpLocation/exportXls',
        importExcelUrl: 'base/erpLocation/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      list1: [],
      options: [],
    }
  },
  created() {
    this.loadDictData()
  },
  mounted() {
    this.$nextTick(() => {
      console.log(this.$refs.location)
      // this.$refs.location.showModal();
    })
  },
  computed: {},
  methods: {
    loadDictData() {
      let row = {}
      console.log('------------------this.containDelete---------------------')

      console.log(this.containDelete)
      if (this.rowData) {
        row = this.rowData.row

        // this.materialId = row.materialId
      }
      if (this.containDelete) {
        getAction('/base/erpSupplier/material/list').then((res) => {
          if (res.success) {
            this.options = res.result
          }
        })
      } else {
        getAction('/base/erpSupplier/list').then((res) => {
          if (res.success) {
            this.options = res.result.records
          }
        })
      }
    },
    confirm() {
      if (this.selectionRows.length > 0) {
        const val = this.selectedRowKeys[0]
        this.values = val
        this.callBack(val)
      }
      this.onClearSelected()
    },
    handerChange(value, option) {
      this.callBack(value)
    },
    callBack(value) {
      getAction('/base/erpSupplier/queryById', { id: value }).then((res) => {
        this.$emit('handlerOk', {
          row: this.rowData ? this.rowData.row : '',
          value: value,
          data: res.result,
        })
      })
    },
    // getLocationInfo(value){
    //   const { row } = this.rowData
    //   const param = {id: value}
    //   getAction('/base/erpLocation/queryInfoById',param).then(res=>{
    //       if (res.success) {
    //         // 向外传递
    //         this.$emit('handlerOk',{
    //           result: res.result,
    //           row: row
    //         });
    //       }
    //   })
    // },
    add() {
      this.showModal()
    },
    showModal() {
      this.visible = true
      this.queryParam = { procurementType: this.procurementType }
      this.loadData()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      // fieldList.push({type:'string',value:'wareHouseId',text:'仓库',dictCode:"erp_warehouse,name,id"})
      fieldList.push({ type: 'string', value: 'code', text: '库位编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '库位名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'erp_status' })
      this.superFieldList = fieldList
    },
    handleCancel() {
      this.close()
    },
    handleOk() {
      this.$emit('handlerOk', this.selectionRows[0])
      this.close()
      // console.log(this.selectionRows[0])
    },
    close() {
      // this.searchReset(false);
      this.queryParam = {}
      this.selectedRowKeys = []
      this.selectionRows = []
      this.visible = false
    },
  },
}
</script>

<style scoped>
/* 覆盖Dropdown菜单项在悬停时的背景颜色 */
.ant-dropdown-menu-item:hover,
.ant-dropdown-menu-submenu-title:hover {
  background-color: inherit; /* 或者设置为初始背景色 */
}
</style>